#pragma once 
#include <iostream>
#include <fstream> // 包含文件流头文件，用于文件操作
using namespace std;

// 松灵小车包括底盘、AGX套件、双目摄像头、多线激光雷达、9轴陀螺仪、液晶显示屏、电池模块这几个大类
#include "Underpan.h"
#include "AGX.h"
#include "Camera.h"
#include "Lidar.h"
#include "Gyroscope.h"
#include "Green.h"
#include "Battery.h"

class Car
{
public:
    string id;           // 编号：自定义，cqusn打头的16位数字+字母
    Underpan underpan;   // 底盘
    AGX agx;            // AGX套件
    Camera camera;       // 双目摄像头
    Lidar lidar;         // 多线激光雷达
    Gyroscope gyroscope; // 9轴陀螺仪
    Green green;        // 液晶显示屏
    Battery battery;     // 电池模块

    // 默认构造函数
    Car() : id(""), underpan(Underpan()), agx(AGX()), camera(Camera()),
             lidar(Lidar()), gyroscope(Gyroscope()), green(Green()), battery(Battery()) {}

    // 构造函数
    Car(string id, Underpan u, AGX a, Camera c, Lidar l,
         Gyroscope g, Green gn, Battery b)
        : id(id), underpan(u), agx(a), camera(c), lidar(l),
          gyroscope(g), green(gn), battery(b) {}

    // 设置编号
    void setID(string newID) {
        id = newID;
    }

    // 打印单个小车的信息
    void const print() {
        cout << "小车编号: " << id << endl;
        cout << "底盘信息:" << endl;
        underpan.print();
        cout << "AGX套件信息:" << endl;
        agx.print();
        cout << "双目摄像头信息:" << endl;
        camera.print();
        cout << "多线激光雷达信息:" << endl;
        lidar.print();
        cout << "9轴陀螺仪信息:" << endl;
        gyroscope.print();
        cout << "液晶显示屏信息:" << endl;
        green.print();
        cout << "电池模块信息:" << endl;
        battery.print();
        cout << "----------------------------------------" << endl;
    }

    // 保存智能小车信息到本地文件
    void save(const string &filename) {
        ofstream outFile(filename, ios::app);  // 以追加模式打开文件
        if (!outFile.is_open()) {
            cerr << "无法打开文件 " << filename << endl;
            return;
        }
        outFile << "小车编号: " << id << endl;
        underpan.save(filename);
        agx.save(filename);
        camera.save(filename);
        lidar.save(filename);
        gyroscope.save(filename);
        green.save(filename);
        battery.save(filename);
        outFile.close();  // 关闭文件流
    }
};